<?php
require_once("common.inc.php");
$message = "";
if(isset($_POST["submit"])){
    $username = $_POST["Username"];
    $password = $_POST["Password"];
    $intro = $_POST["Intro"];
    $sql = "INSERT INTO `account` (`username`,`password`,`intro`)VALUES('$username','$password','$intro')";
    $conn=new mysqli("localhost","root","root","myblog");
    $conn->query($sql);
    if($conn->error) die($conn->error);

    $id = $conn->insert_id;
    if (isset($_FILES["face"])){
        $faceInfo = $_FILES["face"];
        $dest = __DIR__."/faces/$id.jpg";
        move_uploaded_file($faceInfo["tmp_name"],$dest);
        $message = "注册成功";
    }else{
        $dest = __DIR__."/faces/$id.jpg";
        $src = __DIR__."/default-face.jpg";
        copy($src,$dest);
    }
}
?>
<?php require_once("header.inc.php");?>
<form method="POST" action="" enctype="multipart/form-data" class="dataset">
            <div class="field">
            <label>用户名</label><input type="text" name="Username" value="" placeholder="请输入用户名"/>
            </div>
            <div class="field">
            <label>密码</label> <input type="password" name="Password" title="至少输入6个字符" value=""/>
            </div>
            <div class="field">
            <label>头像</label> <input type="file" name="face" title="上传头像" />
            </div>
            <div class="field">
            <label>自我介绍</label>
                <textarea name="Intro" cols="80" rows="10">
                    Hello php!!!
                </textarea>
            </div>
            <div class="actions">
            <input type="submit" name="submit" value="提交"/>
            <input type="reset" name="reset" value="重置"/>
            </div>
        </form>
<?php require_once("footer.inc.php");?>